package org.reenscape.packet;
import org.reenscape.model.*;
import org.reenscape.updater.*;
import org.reenscape.skill.*;
public class PacketItem {

				/**
				* Wields an item on the player.
				*/
				public void Wield(PacketParser p3){
				    int ID = p3.inStream.readUnsignedWord();
					int Slot = p3.inStream.readUnsignedWordA();
					int Interface = p3.inStream.readUnsignedWordA();
					boolean valid = p3.check(ID);
					
					if(!valid){
						Flagger.flag(p3);
						return;
					}
					
					p3.wear(ID, Slot);
					p3.flushOutStream();
				}
				
				/**
				* Moves items in the bank, inventory, etc.
				*/
				public void MoveSlot(PacketParser p3){
					int Junk = p3.inStream.readUnsignedWordA();
					int FromSlot = p3.inStream.readUnsignedWordA();
					int ToSlot = (p3.inStream.readUnsignedWordA() - 128);

					p3.moveItems(FromSlot, ToSlot, Junk);
				}
				
				/**
				* Clicking on an item on the first. Eating etc.
				*/
				public void FirstClick(PacketParser p3){
					int Junk = p3.inStream.readSignedWordBigEndianA();
					int Slot = p3.inStream.readUnsignedWordA();
					int ID = p3.inStream.readUnsignedWordBigEndian();
					boolean valid = p3.check(ID);

					if(!valid){
						Flagger.flag(p3);
						return;
					}
				
					if(Skill.prayer.bury(ID, Slot, p3)) return;
					if(Skill.healing.eat(ID, Slot, p3)) return;
				}
				
				/**
				* Dropping an item onto the floor.
				*/
				public void DropOnFloor(PacketParser p3){
					int ID = p3.inStream.readUnsignedWordA();
					int Junk = p3.inStream.readUnsignedByte() + p3.inStream.readUnsignedByte();
					int Slot = p3.inStream.readUnsignedWordA();
					boolean valid = p3.check(ID);
					
					if(!valid){
						Flagger.flag(p3);
						return;
					}
					
						if(p3.isUntradable(ID)){
							p3.sendMessage("You destroy the item.");
							p3.deleteItem(ID, p3.GetItemSlot(ID), 1);
						} else {
							p3.dropItem(ID, Slot);
						}
				}
				
				/**
				* Picking an item up from the floor and putting it in your inventory.
				*/
				public void PickupFromFloor(PacketParser p3){
					int Y = p3.inStream.readSignedWordBigEndian();
					int ID = p3.inStream.readUnsignedWord();
					int X = p3.inStream.readSignedWordBigEndian();
					if(!p3.pickingUp){
						if(ItemUpdater.itemExists(ID, X, Y)) {
							if(p3.absX == X && p3.absY == Y) {
								int Amount = ItemUpdater.itemAmount(ID, X, Y);
								p3.pickupX = X;
								p3.pickupY = Y;
								p3.pickupID = ID;
								p3.pickupAmt = Amount;
								p3.pickingUp = true;
							}
						}
					}
				}
}